package Sort;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/*
comparator接口实际上是出自 java.util 包它有一个compare(Object obj1, Object obj2)方法用来排序
 */
public class Sort {

  public static void main(String[] args) {

    ArrayList<Integer> list = new ArrayList<>();
    list.add(1);
    list.add(-1);
    list.add(10);
    list.add(5);

//    Collections.sort(list);//默认排序
    Collections.reverse(list);//反转
    Collections.sort(list, new Comparator<Integer>() {
      @Override
      public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
      }
    });
    for (Integer integer : list) {
      System.out.println(integer);
    }
  }
}
